package com.yx.study.leet.primary.other;

/**
 * @Classname ReverseBits
 * @Date 2023/02/12 22:40
 * @Author by yx
 * @Description : 颠倒二进制位
 * https://leetcode.cn/leetbook/read/top-interview-questions-easy/xnc5vg/
 */
public class ReverseBits {
    public int reverseBits(int n) {
        int res = 0;
        for (int i = 0; i < 32; i++) {
            res <<= 1;
            res |= n&1; // 取最后一位,取或 都为0则为0
            n>>=1;
        }
        return res;
    }

}
